/*******************************************************************************
 * createDelegate方法的实现细节省略 createDelegate就是创建代理函数
 * func.createDelegate(scope,args); 返回一个func函数的引用,函数的作用域为scope,传入的参数为args
 * 
 ******************************************************************************/
var sayHi = function(name) {

		// Note this use of "this.text" here. This function expects to
		// execute within a scope that contains a text property. In this
		// example, the "this" variable is pointing to the btn object that
		// was passed in createDelegate below.
		alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
	}
var btn = new Ext.Button({
	text: 'Say Hi',
	renderTo: Ext.getBody()
});

// This callback will execute in the scope of the
// button instance. Clicking the button alerts
// "Hi, Fred. You clicked the "Say Hi" button."
btn.on('click', sayHi.createDelegate(btn, ['cheney']));
btn.fireEvent('click');

var obj = {
	name: "snany",
	doit: function() {
		alert(this.name);
	}
};

function sayName(name) {
	alert('hello, ' + this.name);
}
var sayName2 = sayName.createDelegate(obj, ['jack']);
obj.doit = sayName2;

obj.doit();
